package cn.iocoder.yudao.module.iot.controller.admin.user;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.iot.controller.app.user.vo.IotUserLoginReqVO;
import cn.iocoder.yudao.module.iot.controller.app.user.vo.IotUserLoginRespVO;
import cn.iocoder.yudao.module.iot.controller.app.user.vo.IotUserRegisterReqVO;
import cn.iocoder.yudao.module.iot.controller.app.user.vo.IotUserRespVO;
import cn.iocoder.yudao.module.iot.service.user.IotUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - IoT用户")
@RestController
@RequestMapping("/iot/user")
@Validated
@Slf4j
public class IotUserController {

    @Resource
    private IotUserService iotUserService;

    @PostMapping("/login")
    @Operation(summary = "IoT用户登录")
    public CommonResult<IotUserLoginRespVO> login(@Valid @RequestBody IotUserLoginReqVO reqVO) {
        return success(iotUserService.login(reqVO));
    }

    @PostMapping("/register")
    @Operation(summary = "IoT用户注册")
    public CommonResult<Boolean> register(@Valid @RequestBody IotUserRegisterReqVO reqVO) {
        iotUserService.register(reqVO);
        return success(true);
    }

    @GetMapping("/info")
    @Operation(summary = "获取IoT用户信息")
    public CommonResult<IotUserRespVO> getUserInfo() {
        return success(iotUserService.getCurrentUserInfo());
    }

    @PutMapping("/update")
    @Operation(summary = "更新IoT用户信息")
    public CommonResult<Boolean> updateUserInfo(@Valid @RequestBody IotUserRespVO reqVO) {
        iotUserService.updateUserInfo(reqVO);
        return success(true);
    }
} 